
function getUrl(name) {
    var data = window.location.hash.replace("#", "").replace('?', '').toLowerCase();
    var data2 = data.split("&");
  
    for(var i=0;i < data2.length;i++){
      if(data2[i].indexOf(name) > -1){
        data = data2[i].split("=")[1];
        if(data == undefined){
            data = "";
        }
        return data;
      }
    }
}


// 动态引入css
function includeLinkStyle(url, id) {
    var link = document.createElement("link");
    link.id = id;
    link.rel = "stylesheet";
    link.type = "text/css";
    link.href = url;
    document.getElementsByTagName("head")[0].appendChild(link);
}


// 监听锚点事件
window.onhashchange = function (e) {
    var mode = getUrl("mode");
    if(mode == "1"){
        $("#ui-mode").text("明亮模式");
        includeLinkStyle("css/styles-dark.css", "styles-dark");
    } else{
        $("#ui-mode").text("深色模式")
        $("#styles-dark").remove();
    }
}

window.onhashchange();